package com.spring.sunflower.main.adapter;

import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.makeramen.roundedimageview.RoundedImageView;
import com.spring.sunflower.R;
import com.spring.sunflower.bean.RecommendAnchorsBean;
import com.spring.sunflower.constant.Constant;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * Created by Kevin on 2021/6/1<br/>
 * <p>
 * Describe:<br/>
 */
public class NewDiscoverAdapter extends BaseQuickAdapter<RecommendAnchorsBean.DatasBean, BaseViewHolder> {


    @Override
    public void onAttachedToRecyclerView(@NotNull RecyclerView recyclerView) {
        super.onAttachedToRecyclerView(recyclerView);
    }

    public NewDiscoverAdapter(int layoutResId, @Nullable List<RecommendAnchorsBean.DatasBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, RecommendAnchorsBean.DatasBean recommendAnchorsBean) {
        String coverUrl = recommendAnchorsBean.getCoverUrl();
        Glide.with(getContext())
                .load(TextUtils.isEmpty(coverUrl)?recommendAnchorsBean.getPhoto():coverUrl)
                .into((RoundedImageView) baseViewHolder.getView(R.id.ivCover));
        baseViewHolder.setText(R.id.tvName, recommendAnchorsBean.getNickname());
        baseViewHolder.setText(R.id.tvAge, recommendAnchorsBean.getAge());
//        baseViewHolder.setText(R.id.tvHouse, recommendAnchorsBean.getCity());
        ImageView ivGender = baseViewHolder.getView(R.id.ivGender);
        LinearLayout llGenderContainer = baseViewHolder.getView(R.id.llGenderContainer);
        if (recommendAnchorsBean.getSex().equals(Constant.GENDER_MALE)){
            ivGender.setImageResource(R.drawable.ic_gender_male);
            llGenderContainer.setBackgroundResource(R.drawable.ic_bg_blue_corner_50);
        }else {
            ivGender.setImageResource(R.drawable.ic_gender_female);
            llGenderContainer.setBackgroundResource(R.drawable.ic_bg_pink_corner_50);
        }
        LinearLayout llStatus = baseViewHolder.getView(R.id.llStatus);
        TextView tvStatus = baseViewHolder.getView(R.id.tvStatus);
        ImageView vStatus = baseViewHolder.getView(R.id.vStatus);
        ImageView ivHello = baseViewHolder.getView(R.id.ivHello);
        List<RecommendAnchorsBean.DatasBean.OnlineMoodVBean> onlineMoodV = recommendAnchorsBean.getOnlineMoodV();
        if (recommendAnchorsBean.getStatus().equals("4")) {
            Glide.with(getContext())
                    .load(R.drawable.iv_hello_video)
                    .into(ivHello);
            if (onlineMoodV != null && onlineMoodV.size() > 0) {
                llStatus.setVisibility(View.VISIBLE);
                vStatus.setVisibility(View.VISIBLE);
                tvStatus.setText(onlineMoodV.get(0).getName());
            } else {
                llStatus.setVisibility(View.GONE);
            }


        } else {
            llStatus.setVisibility(View.VISIBLE);
            vStatus.setVisibility(View.GONE);
            tvStatus.setText(recommendAnchorsBean.getLastOnLineTimeDesc());
            Glide.with(getContext())
                    .load(R.drawable.iv_hello)
                    .into(ivHello);
        }
    }
}
